package com.shuma.shopmanage.security.config;

import com.shuma.shopmanage.security.interceptor.HandleInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${shopmanage.ignore:null}")
    private String[] ignore;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration patterns = registry.addInterceptor(new HandleInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**", "/error/**");
        if (ignore != null) {
            patterns.excludePathPatterns(ignore); // 添加拦截器，并指定拦截路径
        }
    }
}